package fr.emse.tatiana.graphical;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * An octogonal graphical figure.
 */
public class Octagon
	extends Shape
{



/** The points of the triangle. */
protected PointList octogon = new PointList(8);

/**
 * @see Shape#fillShape(Graphics)
 */
@Override
protected void fillShape(Graphics g) {
	g.fillPolygon(octogon);
}

/**
 * @see Shape#outlineShape(Graphics)
 */
@Override
protected void outlineShape(Graphics g) {
	g.drawPolygon(octogon);
}

/**
 * @see Figure#primTranslate(int, int)
 */
@Override
public void primTranslate(int dx, int dy) {
	super.primTranslate(dx, dy);
	octogon.translate(dx, dy);
}



/**
 * @see IFigure#validate()
 */
@Override
public void validate() {
	super.validate();
	Rectangle r = new Rectangle();
	r.setBounds(getBounds());
	r.crop(getInsets());
	r.resize(-1, -1);
	int hoffset =(r.width/4);
	int voffset =(r.height/4);
	

	octogon.removeAllPoints();
	octogon.addPoint(new Point(r.x+hoffset,r.y));
	octogon.addPoint(new Point(r.x-hoffset+r.width,r.y));
	octogon.addPoint(new Point(r.x+r.width,r.y+voffset));
	octogon.addPoint(new Point(r.x+r.width,r.y-voffset+r.height));	
	octogon.addPoint(new Point(r.x-hoffset+r.width,r.y+r.height));
	octogon.addPoint(new Point(r.x+hoffset,r.y+r.height));
	octogon.addPoint(new Point(r.x,r.y-voffset+r.height));
	octogon.addPoint(new Point(r.x,r.y+voffset));
	
}

}
